﻿using Microsoft.AspNetCore.Mvc.Filters;
using System.Net.Sockets;
using System.Net;

namespace B.S.BaseData.Api.Read.Files
{
    public class MyConexet : IExceptionFilter
    {
        private readonly ILogger<MyConexet> logger;

        public MyConexet(ILogger<MyConexet> logger)
        {
            this.logger = logger;
        }

        public void OnException(ExceptionContext context)
        {
            var hostName = Dns.GetHostName();
            var hostEntry = Dns.GetHostEntry(hostName);
            var ipAddress = hostEntry.AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);

            logger.LogError("全局异常" + context.Exception.Message);
            context.ExceptionHandled = true;
        }
    }
}
